
#pragma once

#include <vector>
#include "AbstractGraph.h"
#include "MatrixGraph.h"
#include "ListGraph.h"
#include <memory>
#include <algorithm>

namespace {
	size_t getPredictedListGraphSize(int vertexNum, int edgesNum){
		return sizeof(int)*edgesNum + vertexNum*sizeof(std::vector<int>);
	}
	size_t getPredictedMatrixGraphSize(int vertexNum){
		return sizeof(bool)*vertexNum*vertexNum / 8 + vertexNum*sizeof(std::vector<bool>);
	}
	std::unique_ptr<Graph> readGraph(int vertexNum, const std::vector<Edge>& edgesList){
		size_t listSize = getPredictedListGraphSize(vertexNum, edgesList.size());
		size_t matrixSize = getPredictedMatrixGraphSize(vertexNum);
		if (listSize > matrixSize){	 
			std::unique_ptr<MatrixGraph> gettedMatrixGraph(new MatrixGraph(vertexNum, edgesList));
			return std::move(gettedMatrixGraph);
		}
		else{
			std::unique_ptr<ListGraph> gettedListGraph(new ListGraph(vertexNum, edgesList));
			return std::move(gettedListGraph);
		}
	}
}
